﻿<SelectTable Context="clientContext" TItem="Client" @bind-Value="_selectClient" ShowSearch="true" DisplayText="所属单位" Color="Color.Info" OnQueryAsync="OnClientsQueryAsync" GetTextCallback="@GetClientNameCallback">
    <TableColumns>
        <TableColumn @bind-Field="@clientContext.ClientId" Sortable="true" Width="100" Text="单位编码"></TableColumn>
        <TableColumn @bind-Field="@clientContext.ClientName" Sortable="true" Searchable="true" Text="单位名称"></TableColumn>
    </TableColumns>
</SelectTable>

@code {
    private Client? _selectClient;

    private static string? GetClientNameCallback(Client dto)
    {
        return dto.ClientName;
    }

    private Task<QueryData<Client>> OnClientsQueryAsync(QueryPageOptions options)
    {
        IEnumerable<Client> items = new List<Client> {
                new() { ClientId=1,ClientName="测试一" },
                new() { ClientId=2,ClientName="测试二" },
                new() { ClientId=3,ClientName="测试三" },
                new() { ClientId=4,ClientName="测试四" },
                new() { ClientId=5,ClientName="测试五" },
            };

        if (!string.IsNullOrEmpty(options.SortName))
        {
            items = items.Sort(options.SortName, options.SortOrder);
        }

        var count = items.Count();
        if (options.IsPage)
        {
            items = items.Skip((options.PageIndex - 1) * options.PageItems).Take(options.PageItems);
        }

        return Task.FromResult(new QueryData<Client>()
            {
                Items = items.ToList(),
                TotalCount = count,
                IsAdvanceSearch = true,
                IsFiltered = true,
                IsSearch = true,
                IsSorted = true
            });
    }
}
